<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseEmployees {

	protected $m_intId;
	protected $m_intDepartmentId;
	protected $m_intEmployeeTypeId;
	protected $m_strFirstName;
	protected $m_strMiddleName;
	protected $m_strLastName;
	protected $m_strPhoneNumber;
	protected $m_strMobileNumber;
	protected $m_strOfficeNumber;
	protected $m_strEmailAddress;
	protected $m_strAddressLine1;
	protected $m_strAddressLine2;
	protected $m_strArea;
	protected $m_strCity;
	protected $m_strPinCode;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $m_intUpdatedBy;
	protected $m_strUpdatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getDepartmentId(){
		return $this->m_intDepartmentId;
	}

	public function getEmployeeTypeId(){
		return $this->m_intEmployeeTypeId;
	}

	public function getFirstName(){
		return $this->m_strFirstName;
	}

	public function getMiddleName(){
		return $this->m_strMiddleName;
	}

	public function getLastName(){
		return $this->m_strLastName;
	}

	public function getPhoneNumber(){
		return $this->m_strPhoneNumber;
	}

	public function getMobileNumber(){
		return $this->m_strMobileNumber;
	}

	public function getOfficeNumber(){
		return $this->m_strOfficeNumber;
	}

	public function getEmailAddress(){
		return $this->m_strEmailAddress;
	}

	public function getAddressLine1(){
		return $this->m_strAddressLine1;
	}

	public function getAddressLine2(){
		return $this->m_strAddressLine2;
	}

	public function getArea(){
		return $this->m_strArea;
	}

	public function getCity(){
		return $this->m_strCity;
	}

	public function getPinCode(){
		return $this->m_strPinCode;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}

	public function getUpdatedBy(){
		return $this->m_intUpdatedBy;
	}

	public function getUpdatedOn(){
		return $this->m_strUpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setDepartmentId( $DepartmentId ){
		$this->m_intDepartmentId = $DepartmentId;
	}

	public function setEmployeeTypeId( $EmployeeTypeId ){
		$this->m_intEmployeeTypeId = $EmployeeTypeId;
	}

	public function setFirstName( $FirstName ){
		$this->m_strFirstName = $FirstName;
	}

	public function setMiddleName( $MiddleName ){
		$this->m_strMiddleName = $MiddleName;
	}

	public function setLastName( $LastName ){
		$this->m_strLastName = $LastName;
	}

	public function setPhoneNumber( $PhoneNumber ){
		$this->m_strPhoneNumber = $PhoneNumber;
	}

	public function setMobileNumber( $MobileNumber ){
		$this->m_strMobileNumber = $MobileNumber;
	}

	public function setOfficeNumber( $OfficeNumber ){
		$this->m_strOfficeNumber = $OfficeNumber;
	}

	public function setEmailAddress( $EmailAddress ){
		$this->m_strEmailAddress = $EmailAddress;
	}

	public function setAddressLine1( $AddressLine1 ){
		$this->m_strAddressLine1 = $AddressLine1;
	}

	public function setAddressLine2( $AddressLine2 ){
		$this->m_strAddressLine2 = $AddressLine2;
	}

	public function setArea( $Area ){
		$this->m_strArea = $Area;
	}

	public function setCity( $City ){
		$this->m_strCity = $City;
	}

	public function setPinCode( $PinCode ){
		$this->m_strPinCode = $PinCode;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}

	public function setUpdatedBy( $UpdatedBy ){
		$this->m_intUpdatedBy = $UpdatedBy;
	}

	public function setUpdatedOn( $UpdatedOn ){
		$this->m_strUpdatedOn = $UpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into EMPLOYEES (department_id, employee_type_id, first_name, middle_name, last_name, phone_number, mobile_number, office_number, email_address, address_line1, address_line2, area, city, pin_code, created_by, created_on, updated_by, updated_on) values (" . $this->getDepartmentId() . ", " . $this->getEmployeeTypeId() . ", '" . $this->getFirstName() . "', '" . $this->getMiddleName() . "', '" . $this->getLastName() . "', '" . $this->getPhoneNumber() . "', '" . $this->getMobileNumber() . "', '" . $this->getOfficeNumber() . "', '" . $this->getEmailAddress() . "', '" . $this->getAddressLine1() . "', '" . $this->getAddressLine2() . "', '" . $this->getArea() . "', '" . $this->getCity() . "', '" . $this->getPinCode() . "', " . $this->getCreatedBy() . ", now() , " . $this->getUpdatedBy() . ", NULL )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE EMPLOYEES set  department_id= " . $this->getDepartmentId() . ", employee_type_id= " . $this->getEmployeeTypeId() . ", first_name= '" . $this->getFirstName() . "', middle_name= '" . $this->getMiddleName() . "', last_name= '" . $this->getLastName() . "', phone_number= '" . $this->getPhoneNumber() . "', mobile_number= '" . $this->getMobileNumber() . "', office_number= '" . $this->getOfficeNumber() . "', email_address= '" . $this->getEmailAddress() . "', address_line1= '" . $this->getAddressLine1() . "', address_line2= '" . $this->getAddressLine2() . "', area= '" . $this->getArea() . "', city= '" . $this->getCity() . "', pin_code= '" . $this->getPinCode() . "', created_by= " . $this->getCreatedBy() . ", updated_by= " . $this->getUpdatedBy() . ",updated_on = now()  where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM employees WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'employees'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}